/**
 * 
 */
define(function (require, exports, module) {
	var EditGrid = require("editgrid");
	
    var instance = {
        initComponent: function (params,widget,roomRegisters) {
        	
        	var selectRoomData = [];
        	var selectRoomDataObj = {};
        	if(!roomRegisters){
        		roomRegisters = [];
        	}
			for(var i=0;i<roomRegisters.length;i++){
				var register = roomRegisters[i];
				
				selectRoomDataObj[register.pkRoomRegister] = register;
				
				selectRoomData.push({
					key: register.pkRoomRegister,
					value: register.room.orgBuilding.name + "-" + register.room.code
				});
			}
        	
        	
        	$("#roomPersonalInfos").html("");
        	var grid = new EditGrid({
        		parentNode:"#roomPersonalInfos",
        		model:{
        			id : "checkInRoomGrid",
        			allowAdd : false,
        			columns:[{
        				name:"signUpRegister.personalInfo.name",
        				label:"姓名",
        			},{
        				name:"signUpRegister.personalInfo.idNumber",
        				label:"身份证号",
        			},{
        				name:"signUpRegister.personalInfo.sex.value",
        				label:"性别",
        				readonly:true,
        			},{
        				name:"signUpRegister.personalInfo.mobilePhone",
        				label:"联系电话",
        			},{
        				name:"roomRegisterRoom",
        				label:"分配房间",
        				className: "col-md-2",
        				format:function(value,data){
        					if(data.roomRegister && data.roomRegister.room){
        						return data.roomRegister.room.orgBuilding.name + "-" + data.roomRegister.room.code
        					}else{
        						return "";
        					}
        				},
        				editor:{
							type:"select",
							options:selectRoomData,
							/*onBeforeEdit:function(data){
								if(data.signUpRegister.exitGroup == false){
									return false;	
								}else{
									return true;
								}
							},*/
							onEdit:function(editor,rowIndex,rowData){
								editor.setValue(rowData.key);
							},
							onChange:function(plugin,index,rowData){
								rowData.roomRegister = selectRoomDataObj[plugin.getValue()];
								grid.update(index,rowData);
							}
						},
        			},{
        				name:"descript",
        				label:"备注",
        				editor:{
							type:"text",
							placeholder: "请输入备注",
							onEdit:function(editor,rowIndex,rowData){
								editor.setValue(rowData.descript);
							},
							onChange:function(plugin,index,rowData){
								rowData.descript = plugin.getValue();
								grid.update(index,rowData);
							}
						}
						
        			}]
        		}
        	});
        	widget.set("checkInRoomGrid",grid);
        }
    };
    module.exports = instance;
});


